//
//  SiteDetailPageViewController.m
//  Interface
//
//  Created by Letme on 15-4-13.
//  Copyright (c) 2015年 zhenjiea. All rights reserved.
//

#import "SiteDetailPageViewController.h"

@interface SiteDetailPageViewController ()

@end

@implementation SiteDetailPageViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view.
    self.view.backgroundColor = [UIColor whiteColor];
    
#warning 数组初始化
    self.infoArray = [NSMutableArray array];
    
    if (![self.model.description2 isEqualToString:@""]) {
        NSString *str = [NSString stringWithFormat:@"📖 概览:%@", self.model.description2];
        [self.infoArray addObject:str];
    }
    if (![self.model.address isEqualToString:@""]) {
        NSString *str = [NSString stringWithFormat:@"📬 地址:%@", self.model.address];
        [self.infoArray addObject:str];
    }
    if (![self.model.arrival_type isEqualToString:@""]) {
        NSString *str = [NSString stringWithFormat:@"🚍 到达方式:%@", self.model.arrival_type];
        [self.infoArray addObject:str];
    }
    if (![self.model.opening_time isEqualToString:@""]) {
        NSString *str = [NSString stringWithFormat:@"⌚️ 开放时间:%@", self.model.opening_time];
        [self.infoArray addObject:str];
    }
    if (![self.model.fee isEqualToString:@""]) {
        NSString *str = [NSString stringWithFormat:@"💰 人均消费:%@", self.model.fee];
        [self.infoArray addObject:str];
    }
    
    
    
    self.myTableView = [[UITableView alloc] initWithFrame:CGRectMake(0, 0, self.view.frame.size.width, self.view.frame.size.height - 49) style:UITableViewStylePlain];
    self.myTableView.delegate = self;
    self.myTableView.dataSource = self;
    [self.view addSubview:self.myTableView];
    [_myTableView release];
    
    UIView *headView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, self.view.frame.size.width, self.view.frame.size.height - 49)];
    //headView.backgroundColor = [UIColor greenColor];
    [self.myTableView addSubview:headView];
    self.myTableView.tableHeaderView = headView;
    
    
    UIImageView *myImageView = [[UIImageView alloc] initWithFrame:CGRectMake(0, 0, self.view.frame.size.width, (self.view.frame.size.height - 49) / 2)];
    //myImageView.backgroundColor = [UIColor yellowColor];
    [headView addSubview:myImageView];
    myImageView.userInteractionEnabled = YES;
#warning 轻拍
    UITapGestureRecognizer *tap = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(tapAction:)];
    [myImageView addGestureRecognizer:tap];
    [tap release];
    
#warning 异步
    NSURL *url = [NSURL URLWithString:self.model.cover_route_map_cover];
    [myImageView sd_setImageWithURL:url placeholderImage:[UIImage imageNamed:@"06b1OOOPICf5.jpg"]];
    
    
    
    UILabel *nameenLabel = [[UILabel alloc] initWithFrame:CGRectMake(20, myImageView.frame.size.height - 30, self.view.frame.size.width, 30)];
    nameenLabel.text = self.model.name_en;
    [myImageView addSubview:nameenLabel];
    
    nameenLabel.textColor = [UIColor whiteColor];
    //nameenLabel.textColor = [UIColor whiteColor];
    [nameenLabel release];
    
    UILabel *nameLabel = [[UILabel alloc] initWithFrame:CGRectMake(0 , myImageView.frame.origin.y + myImageView.frame.size.height + 30, self.view.frame.size.width, self.view.frame.size.height / 10)];
    //nameLabel.backgroundColor = [UIColor yellowColor];
    nameLabel.text = self.model.name;
    //nameenLabel.textAlignment =  NSTextAlignmentCenter;
    nameLabel.font = [UIFont systemFontOfSize:25];
#warning 居中
    nameLabel.textAlignment = NSTextAlignmentCenter;
    [headView addSubview:nameLabel];
    
    UILabel *reasonLabel = [[UILabel alloc] initWithFrame:CGRectMake(20, nameLabel.frame.origin.y + nameLabel.frame.size.height + 10, self.view.frame.size.width - 40, 60)];
    reasonLabel.text = self.model.recommended_reason;
    reasonLabel.font = [UIFont systemFontOfSize:15];
    //reasonLabel.backgroundColor = [UIColor redColor];
    reasonLabel.textAlignment = NSTextAlignmentCenter;
    reasonLabel.numberOfLines = 0;
    [headView addSubview:reasonLabel];
    [reasonLabel release];
    
    
    UILabel *myLabel = [[UILabel alloc] initWithFrame:CGRectMake(0, reasonLabel.frame.origin.y + reasonLabel.frame.size.height, self.view.frame.size.width, 50)];
    //myLabel.backgroundColor = [UIColor redColor];
    myLabel.text = @"基本信息";
    myLabel.textAlignment = NSTextAlignmentCenter;
    [headView addSubview:myLabel];
    [myLabel release];
}

- (void)tapAction:(UITapGestureRecognizer *)tap
{
    NSString *str = self.model.url_id;
    NSString *name = self.model.name;
    PictureViewController *picVC = [[PictureViewController alloc] init];
    picVC.url_str = str;
    picVC.name = name;
    NSLog(@"%@", str);
    [self.navigationController pushViewController:picVC animated:YES];
}



- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView
{
    return self.infoArray.count;
}

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
    return 1;
}

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
    static NSString *cellIdentifier = @"cell";
    UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:cellIdentifier];
    if (cell == nil) {
        cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:cellIdentifier];
    }
    cell.textLabel.text = [self.infoArray objectAtIndex:indexPath.section];
    cell.textLabel.numberOfLines = 0;
    cell.textLabel.font = [UIFont systemFontOfSize:15];
    return cell;
}
- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath
{
    return [self getHeighContent:[self.infoArray objectAtIndex:indexPath.section]] + 50;
#warning code will be never be exe
    NSLog(@"....................");
}

-  (CGFloat)getHeighContent:(NSString *)content
{
    CGSize size = CGSizeMake(300, 2000);
    NSDictionary *dic = [NSDictionary dictionaryWithObject:[UIFont systemFontOfSize:15] forKey:NSFontAttributeName];
    
    CGRect fram = [content boundingRectWithSize:size options:NSStringDrawingUsesLineFragmentOrigin attributes:dic context:nil];
    
    return fram.size.height;
    
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
